/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.unifor.redes1.odirabel.gui.server;

import java.util.Vector;

/**
 *
 * @author pedro
 */
public class ClientesBuffer {

    private Vector<Cliente> list;

    public ClientesBuffer() {
        list = new Vector<Cliente>();
    }

    public synchronized Vector getLista() {
        return list;
    }

    public synchronized void add(Cliente cliente) {
        list.add(cliente);
    }

    public synchronized String listUsers() {
        String retorno = "";
        Cliente aux;
        for (int i = 0; i < list.size(); i++) {
            aux = list.get(i);
            retorno += aux.getLogin() + " " + aux.getIp();
            if (i != list.size() - 1) {
                retorno += " ";
            }
        }
        return retorno;
    }

    public synchronized void removeUser(Cliente cliente) {
        list.remove(cliente);
    }

    public synchronized Cliente getCliente(Cliente c){
        return list.get(list.indexOf(c));
    }
}
